//
//  AmuseCell.swift
//  swiftDemo
//
//  Created by Gerry on 2022/1/10.
//

import UIKit

class AmuseCell: UICollectionViewCell {
    var itemModel : RoomItem? {
        didSet {
            titleLab.text = itemModel?.room_name
            nickNameLab.text = itemModel?.nickname
            imgView.sd_setImage(with: URL.init(string: itemModel?.vertical_src ?? ""), completed: nil)
        }
    }
    var imgView : UIImageView = UIImageView()
    var titleLab : UILabel = UILabel()
    var nickNameLab : UILabel = UILabel()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.layer.cornerRadius = 10;
        contentView.layer.masksToBounds = true
        contentView.backgroundColor = UIColor.white
        
        contentView.addSubview(imgView)
        imgView.contentMode =  .scaleAspectFill
        imgView.clipsToBounds = true
        imgView.snp.makeConstraints { make in
            make.left.top.right.equalTo(0)
            make.height.equalTo(100)
        }
        
        contentView.addSubview(titleLab)
        titleLab.font = UIFont.systemFont(ofSize: 14)
//        titleLab.numberOfLines = 1
//        titleLab.lineBreakMode = .byWordWrapping
        titleLab.snp.makeConstraints { make in
            make.left.equalTo(8)
            make.right.equalTo(-8)
            make.top.equalTo(imgView.snp.bottom).offset(5)
        }
        
        contentView.addSubview(nickNameLab)
        nickNameLab.font = UIFont.systemFont(ofSize: 12)
        nickNameLab.textColor = UIColor.init(r: 200.0, g: 200.0, b: 200.0)
        nickNameLab.snp.makeConstraints { make in
            make.left.equalTo(8)
            make.right.equalTo(-8)
            make.top.equalTo(titleLab.snp.bottom).offset(5)
            make.bottom.equalTo((self.contentView)).offset(-10)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
